package com.ruoyi.contract.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.ip.IpUtils;

import com.ruoyi.contract.domain.ConOperLog;
import com.ruoyi.contract.mapper.ConOperLogMapper;
import com.ruoyi.contract.service.IConOperLogService;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by zhangxiang on 2021/9/30.
 */
@Service
public class ConOperLogServiceImpl extends ServiceImpl<ConOperLogMapper, ConOperLog> implements IConOperLogService {

    @Override
    public boolean saveConOperLog(Long conId, String title, String detail) {
        ConOperLog conOperLog = new ConOperLog();
        conOperLog.setConId(conId);
        conOperLog.setTitle(title);
        conOperLog.setOperDetail(detail);

        String username = SecurityUtils.getUsername();
        if (StringUtils.isNotBlank(username))
        {
            conOperLog.setOperName(username);
        }
        // 请求的地址
        String ip = IpUtils.getIpAddr(ServletUtils.getRequest());
        conOperLog.setOperIp(ip);
        conOperLog.setOperTime(new Date());
        return this.save(conOperLog);
    }
}
